﻿@using Partner.Surround.Web.Startup
@using Partner.Surround.Authorization
@{
    ViewBag.CurrentPageName = PageNames.Tenants;
}

<!--租户列表-->
<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-card-body">
            <div class="layui-row">
                <div class="layui-col-xs12">
                    <table class="layui-table"
                           lay-data="{height: 'full-60', page:false, id:'tenantList'}"
                           lay-filter="tenantList" lay-size="xs">
                        <thead>
                            <tr>
                                <th lay-data="{field:'tenancyName'}">租户编码</th>
                                <th lay-data="{field:'name'}">租户名称</th>
                                @if (await PermissionChecker.IsGrantedAsync(PermissionNames.Pages_Frame_Tenants_MoveTenantToAnotherEdition))
                                {
                                    <th lay-data="{align:'center',toolbar:'#tenantBarList'}"></th>
                                }
                            </tr>
                        </thead>
                    </table>
                </div>
            </div>
        </div>
    </div>
</div>

<!--列表按钮-->
<script type="text/html" id="tenantBarList">
    <div class="layui-table-cell laytable-cell-1-0-9">
        @if (await PermissionChecker.IsGrantedAsync(PermissionNames.Pages_Frame_Tenants_MoveTenantToAnotherEdition))
        {
            <a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="move">切换版本</a>
        }
    </div>
</script>

@section Scripts{
    <script type="text/javascript">
        layui.config({
            base: "/lib/layui-extend-modules/"
        }).use(['jquery','table'], function () {
            var $ = layui.$,
                table = layui.table;

            //加载表格数据
            var loadTenantList = function () {
                table.reload('tenantList', {
                    url: "@Url.Action("GetTenantList", "Tenants")",
                    parseData: function (res) {
                        return {
                            "code": res.result.code,
                            "msg": res.result.msg,
                            "count": res.result.count,
                            "data": res.result.data
                        };
                    },
                    response: {
                        statusCode: 200
                    }
                });
            };
            loadTenantList();

            //监听工具条
            table.on('tool(tenantList)', function (obj) {
                var data = obj.data;
                if (obj.event === 'move') {   //删除
                    parent.layer.open({
                        type: 2,
                        title: "版本切换",
                        content: "@Url.Action("MoveTenantToAnotherEdition", "Tenants")" + abp.utils.formatString("?id={0}", data.id),
                        area: ["500px", "400px"],
                        btn: ['确定', '取消'],
                        yes: function (index, layero) {
                            parent.window['layui-layer-iframe' + index].layui.submitForm();
                        }
                    });
                }
            });

            //创建或更新完毕回调
            layui.callback = function (data) {
                parent.layer.close(data.index); //关闭弹层
                abp.notify.success(data.msg);
                loadTenantList();
            }
        });
    </script>
}



